package zhoufu.sz.sanxiao_check.ui.adapter;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.view.View;
import android.widget.ImageView;
import com.bumptech.glide.Glide;
import java.util.List;
import org.byteam.superadapter.list.BaseViewHolder;
import org.byteam.superadapter.list.SuperAdapter;
import zhoufu.sz.sanxiao_check.R;
import zhoufu.sz.sanxiao_check.utils.TextUtils;

/**
 * User:RCP
 * email:ruancaipu@gmail.com
 * Date:2016/7/30
 */
public class GridAdapter extends SuperAdapter<String>
{


    private boolean isAdd;

    public GridAdapter(Context context, List<String> data, int layoutResId, boolean isAdd)
    {
        super(context, data, layoutResId);
        this.isAdd = isAdd;
    }

    @Override
    public int getCount()
    {
        if ( mList.size() == 3 || !isAdd )
        {
            return mList.size();
        } else
        {
            return mList.size() + 1;
        }
    }

    @Override protected void onBind(int viewType, BaseViewHolder holder, int position, String item)
    {
        if ( position == mList.size() && isAdd )
        {
            holder.setImageBitmap(R.id.mGridIv, BitmapFactory.decodeResource(
                    getContext().getResources(), R.drawable.add_photo));
            if ( position == 3 )
            {
                holder.getItemView().setVisibility(View.GONE);
            }
        } else
        {
            if ( !TextUtils.isEmpty(item) )
            {
                ImageView iv = holder.getView(R.id.mGridIv);
                iv.setTag(R.string.app_name, "ss");
                Glide.with(getContext()).load(mList.get(position)).into(iv);
            }
        }
    }
}
